<template>
  <div class="app-container">
    <el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="100px" style="width: 400px; margin-left:50px;">
      <el-form-item label="项目名称" prop="projectName">
        <el-input v-model="activity.projectName" />
      </el-form-item>
      <el-form-item label="渠道" prop="userName">
        <el-input v-model="temp.userName" />
      </el-form-item>
      <el-form-item label="商品金额" prop="skuPrice">
        <el-input-number v-model="temp.skuPrice" />
      </el-form-item>
      <el-form-item label="账号" prop="account">
        <el-input v-model="temp.account" />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="temp.password" />
      </el-form-item>
      <el-form-item label="姓名" prop="receiveName">
        <el-input v-model="temp.receiveName" />
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input v-model="temp.phone" />
      </el-form-item>
      <el-form-item label="地址" prop="receiveAddress">
        <el-input v-model="temp.receiveAddress" type="textarea" :rows="9" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm()">立即创建</el-button>
        <el-button @click="resetForm()">重置</el-button>
        <el-button @click="auto()">一键识别</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { Notification, MessageBox, Message } from 'element-ui'
import { tableInfo, crudUtil } from '@/utils/future/toolkit'
import { fetchActivity, createOrder, autoDiscern } from '@/api/purch/share'
export default {
  name: 'ShareForm',

  data() {
    const tableData = {
      activity: {},
      temp: {}
    }
    return Object.assign(tableData, tableInfo)
  },
  created() {
    const shareNum = this.$route.query.shareNum
    fetchActivity(shareNum).then(res => {
      this.activity = res
      console.log(res)
    })
  },

  methods: {
    resetForm() {
      this.$refs['dataForm'].resetFields()
    },
    submitForm() {
      var that = this
      that.temp.purchActivityId = this.activity.id
      that.temp.projectName = this.activity.projectName
      that.temp.skuImgs = 'https://ssl3.sephorastatic.cn/products/5/1/9/4/8/8/1_n_09014_150x150.jpg'
      createOrder(that.temp).then(res => {
        Notification({ title: 'Success', message: '操作成功', type: 'success', duration: 2000 })
        that.resetForm()
      })
    },
    auto() {
      var that = this
      autoDiscern(that.temp).then(res => {
        that.temp = res
        Notification({ title: 'Success', message: '操作成功', type: 'success', duration: 2000 })
      })
    }
  }
}
</script>

<style>

</style>
